﻿@using ComputerBeacon.Facebook.Fql
@using PEETS.Enums
@using PEETS.Models;
@using Microsoft.AspNet.Identity;
@model PEETS.Models.OfferModel

@{
    ViewBag.Title = "Gérer votre compte";
}

<h3>Gérer les offres.</h3>

@{
    if (!string.IsNullOrEmpty(@Model.Message))
    {
        <div id="alert"
             @if (@Model.TypeMessage == @TypeMessage.Succes) 
             { <text> class="alert alert-success collapse" </text>    } 
             else if (@Model.TypeMessage == @TypeMessage.Erreur) 
             { <text> class="alert alert-danger collapse" </text>   } 
             else { <text> class="alert alert-warning collapse" </text>  }
         >
            <a href="#" data-dismiss="alert" class="close">&times;</a>
            @Model.Message
        </div>

        <script>
            (function () {
                document.getElementById("alert").style.display = 'block';
            })();       
        </script>
    }
}

<div style="padding-top: 7px;padding-bottom: 40px" class="col-md-6">
    @*<label style="width: 180px">Code ISBN</label> @Html.TextBoxFor(m => m.Livre.CodeIsbn, null, new { style = "width: 200px" }) <span style="font-weight: bolder;color: red"> *</span>*@
    <a href="#addOfferDialog" class="btn btn-warning btn-lg glyphicon-plus" data-toggle="modal"> Ajouter une offre</a>
</div>

<div>
    @if (@Model.ListeOffresUtil == null)
    {
        <div>Vous n'avez aucune offre présentement.</div>
    }
    else
    {        
        <div class="row">
            <div class="col-md-10">
                <div class="table-responsive">
                    <h3 style="color: red">Liste de vos offres actives</h3>
                    <table class="table table-striped table-bordered table-hover table-condensed">
                        <thead style="font-weight: bold;text-align: center">
                            <tr>
                                <th>No offre</th>
                                <th>Livre</th>
                                <th>Détails</th>
                                <th>Fermer l'offre</th>
                            </tr>
                        </thead>
                        @foreach (var offre in @Model.ListeOffresUtil)
                        {
                            <tr>
                                <td style="text-align: center">
                                    @offre.NoOffre 
                                </td>
                                <td>@offre.NomLivre</td>
                                <td style="text-align: center">
                                    @using (Ajax.BeginForm("GetDetailsJson", new { noOffre = @offre.NoOffre },
                                        new AjaxOptions
                                        {
                                            OnSuccess = "DetailsOnSuccess",
                                            OnFailure = "DetailsOnFailure"
                                        }))
                                    {
                                        <p style="padding-top: 5px"><input class="btn btn-danger btn-xs" value="Détails" type="submit" id="btnOffre_@offre.NoOffre" data-toggle="modal" /></p>
                                    }
                                </td>   
                                <td style="text-align: center">
                                    @using (Ajax.BeginForm("GetDetailsJson", new { noOffre = @offre.NoOffre },
                                        new AjaxOptions
                                        {
                                            OnSuccess = "ModifOnSuccess",
                                            OnFailure = "DetailsOnFailure"
                                        }))
                                    {
                                        <p style="padding-top: 5px"><input class="btn btn-danger btn-xs" value="Modifier" type="submit" id="btnOffre_@offre.NoOffre" data-toggle="modal" /></p>
                                    }
                                </td>                            
                                <td style="text-align: center;padding-top: 10px"><a onclick="AfficherModalFermeture('@offre.NoOffre', '@offre.NomLivre')" class="btn btn-danger btn-xs">Fermer</a>
                                </td>
                                
                            @{

                            if (offre.estNouv)
                            {
                                <td>
                                    <span style="color: red"> * Nouveau</span>
                                </td>
                            }

                            }

                            </tr>
                        }
                    </table>
                </div>
            </div>
        </div>
    }
</div>
    @using (Html.BeginForm("Create", "Offer", FormMethod.Post))
    {
        <div class="modal fade" id="addOfferDialog" tabindex="-1">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header" style="background-color: #aa4200">
                        <a href="#" class="close" data-dismiss="modal">&times;</a>
                        <h4 style="color: white!important">Ajout d'une offre</h4>
                    </div>
                    <div class="modal-body">

                        <div>
                            <label style="width: 180px">Code ISBN</label> @Html.TextBoxFor(m => m.Livre.CodeIsbn, null, new { style = "width: 200px" }) 
                            <span style="font-weight: bolder;color: red"> *</span>
                            @Html.ValidationMessageFor(m => m.Livre.CodeIsbn)
                        </div>
                        
                        <div>
                            <label style="width: 180px">Titre</label><span id="titreLivre" style="padding-left: 3px"></span>
                        </div>
                        
                        <div>
                            <label style="width: 180px">Auteur(s)</label><span id="ateurLivre" style="padding-left: 3px"></span>
                        </div>

                        <div>
                            <label style="width: 180px">État</label> @Html.DropDownListFor(m => m.SelectedEtat, Model.Etats, new { style = "width: 200px" })
                        </div>

                        <div>
                            <label style="width: 180px">Obligatoire pour cours</label> @Html.TextBoxFor(m => m.CoursObligatoires, null, new { style = "width: 200px", placeholder = "Ex: MAT165, MAT472" })
                        </div>

                        <div>
                            <label style="width: 180px">Recommandé pour cours</label> @Html.TextBoxFor(m => m.CoursReferences, null, new { style = "width: 200px", placeholder = "Ex: GIA400, ELE200" })
                        </div>

                        <div>
                            <label style="width: 180px">Remarques**</label>
                            @Html.TextAreaFor(m => m.Remarques, htmlAttributes: new { style = "width: 300px;height: 80px" })
                            @Html.ValidationMessageFor(m => m.Remarques)
                        </div>
                        <div style="padding-top: 7px;color: orangered">
                            <p>
                                **Vous devez indiquez dans le champ remarques, si vous voulez échanger le livre ou le vendre.
                                Si vous l'échangez, vous pouvez indiquer le livre contre lequel vous voulez l'échanger. Si vous le vendez, il faut indiquer le prix demandé.
                                Nous encourageons les échanges de livres entre les étudiants.
                            </p>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <span class="form-group">
                            <input type="submit" class="btn btn-success btn-sm" value="Ajouter" />
                        </span>
                        <button class="btn btn-danger btn-sm" data-dismiss="modal"> Annuler</button>
                    </div>
                </div>
            </div>
        </div>
    }

<div class="modal fade" id="detailsDialog" tabindex="-1">
    <div class="modal-dialog modal-dialog modal-vertical-centered">
        <div class="modal-content">
            <div class="modal-header" style="background-color: #9a161a">
                <a href="#" class="close" data-dismiss="modal">&times;</a>
                <h4 style="color: white!important">Détails sur le livre <span id="headerDetails"></span></h4>
            </div>
            <div class="modal-body" style="height: 400px">

                <div> <div> <label style="font-weight: bold;width: 190px">Titre: </label><span id="nomLivre"></span></div></div>
                <div> <div> <label style="font-weight: bold;width: 190px">Sous-titre: </label><span id="sousTitre"></span></div></div>
                <div> <div> <label style="font-weight: bold;width: 190px">Code ISBN 10: </label><span id="codeIsbn10"></span></div></div>
                <div> <div> <label style="font-weight: bold;width: 190px">Code ISBN 13: </label><span id="codeIsbn13"></span></div></div>
                <div> <div> <label style="font-weight: bold;width: 190px">Obligatoire pour cours: </label><span id="coursOblig"></span></div></div>
                <div> <div> <label style="font-weight: bold;width: 190px">Recommandé pour cours: </label><span id="coursRecom"></span></div></div>
                <div> <div> <label style="font-weight: bold;width: 190px">Auteur(s): </label><span id="auteurLivre"></span></div></div>
                <div> <div> <label style="font-weight: bold;width: 190px">État: </label><span id="etatLivre"></span></div></div>
                <div> <div> <label style="font-weight: bold;width: 190px">Remarques: </label><span id="remLivre"></span></div></div>

                <fieldset style="margin-top: 40px">
                    <legend>Information sur l'offrant</legend>
                    <div> <div> <label style="font-weight: bold;width: 170px">Courriel: </label><a id="courrProprio"></a></div></div>
                    <div> <div> <label style="font-weight: bold;width: 170px">Téléphone: </label><span id="telProprio"></span></div></div>
                </fieldset>

            </div>
            <div class="modal-footer">
                <button class="btn btn-danger btn-sm" data-dismiss="modal"> Fermer</button>
            </div>
        </div>
    </div>
</div>

    <div class="modal fade" id="modifDialog" tabindex="-1">
        <div class="modal-dialog modal-dialog modal-vertical-centered">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #9a161a">
                    <a href="#" class="close" data-dismiss="modal">&times;</a>
                    <h4 style="color: white!important">Modification de l'offre <span id="idOffre"></span></h4>
                </div>
                <div class="modal-body" style="height: 400px">

                    <div> <div> <label style="font-weight: bold;width: 190px">Titre: </label><span id="nomLivreModif"></span></div></div>
                    <div> <div> <label style="font-weight: bold;width: 190px">Obligatoire pour cours: </label><input id="coursObligModif"></div></div>
                    <div> <div> <label style="font-weight: bold;width: 190px">Recommandé pour cours: </label><input id="coursRecomModif"></div></div>
                    <div>
                        <label style="font-weight: bold;width: 187px">État</label> @Html.DropDownListFor(m => m.SelectedEtatModif, Model.Etats, new { style = "width: 218px" })
                    </div>               
                    <div> <div> <label style="font-weight: bold;width: 190px">Remarques: </label><input id="remLivreModif"></div></div>

                </div>
                <div class="modal-footer">
                    <input type="submit" onclick="ModifierOffre()" class="btn btn-success btn-sm" value="Modifier" />
                    <button class="btn btn-danger btn-sm" data-dismiss="modal"> Fermer</button>
                </div>
            </div>
        </div>
    </div>

@using (Html.BeginForm("DesactiverOffre", "Offer", FormMethod.Post))
{
    <div class="modal fade" id="fermerOfferDialog" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #aa4200">
                    <a href="#" class="close" data-dismiss="modal">&times;</a>
                    <h4 style="color: white!important">Fermeture de l'offre </h4>
                </div>
                <div class="modal-body">

                    <div>
                        <label style="width: 180px">Nom du livre: </label> <span id="lbNomFerme"></span>
                    </div>

                    <div>
                        <label style="width: 180px">Raison de la fermeture: </label> @Html.DropDownListFor(m => m.SelectedRaison, Model.ListeRaisons(), new { style = "width: 200px" })
                    </div>

                    <div>
                        <label style="width: 180px">Détails: </label> @Html.TextAreaFor(m => m.DétailsFermeture, new { style = "width: 200px" })
                    </div>
                </div>
                <div class="modal-footer">
                    <span class="form-group">
                        <input type="submit" class="btn btn-warning btn-sm" value="Confirmer" />
                    </span>
                    @Html.HiddenFor(m => m.NoOffre)
                    <button class="btn btn-danger btn-sm" data-dismiss="modal"> Annuler</button>
                </div>
            </div> 
        </div>
    </div>
}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    <script src="~/Scripts/bootstrap-filestyle-0.1.0.min.js"> </script>
}
